package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组;

import java.util.Scanner;

/**
 * @Title: 蜗牛暴力
 * @Author 贾金博
 * @Package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组
 * @Date 2024/4/9 20:58
 * @description:
 */
public class 蜗牛暴力 {
    public static double ret = 1e19;
    public static int n;
    public static int[] a;
    public static int[] b;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         n = sc.nextInt();
         int[] x = new int[n]; // x轴的坐标
         a = new int[n + 10];
         b = new int[n + 10];

        for (int i = 1; i <= (n - 1); i++) {
            a[i] = sc.nextInt();
            b[i + 1] = sc.nextInt();
        }

        dfs(1, 0.0);

        System.out.printf("%.2f", ret);
    }

    public static void dfs(int len, double sum) {
        if(len == n) {
            ret = Math.min(ret, sum);
            return;
        }
        dfs(len + 1, sum + Math.abs(a[len] - a[len - 1]) * 1.0);
        dfs(len + 1, sum + Math.abs(b[len] - a[len]));
    }
}
